const defaultState = {
  todoList: [],
};
function reducers(state = defaultState, action) {
  // 数据处理逻辑
  let todoArr = [];
  switch (action.type) {
    case "add":
      todoArr = [...state.todoList, action.value];
      return {
        todoList: todoArr,
      };
    case "check":
      todoArr = state.todoList.map((el, key) => {
        if (el.id === action.value.id) {
          el.done = action.value.done;
        }
        return el;
      });
      return {
        todoList: todoArr,
      };
    case "deleteDone":
      let includes = action.value;
      todoArr = state.todoList.filter((el) => !includes.includes(el.id));
      return {
        todoList: todoArr,
      };
    case "deleteSelect":
      let { id } = action.value;
      todoArr = state.todoList.filter((el) => el.id !== id);
      return {
        todoList: todoArr,
      };
    case "getData":
      console.log(action.value);
      return {
        todoList: action.value,
      };
    default:
      return state;
  }
}

export default reducers;
